package com.example.dao;

import com.example.domain.Report;
import org.apache.ibatis.annotations.*;

import java.util.List;
//举报记录的操作
public interface ReportMapper {

    @Insert("INSERT INTO report (post_id, comment_id, user_id, reason, status) VALUES (#{postId}, #{commentId}, #{userId}, #{reason}, #{status})")
    void save(Report report);

    @Select("SELECT * FROM report WHERE status = 'pending' ORDER BY create_time DESC")
    @Results(id = "reportMap", value = {
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "post_id", property = "postId"),
            @Result(column = "comment_id", property = "commentId"),
            @Result(column = "user_id", property = "userId"),
            @Result(column = "reason", property = "reason"),
            @Result(column = "create_time", property = "createTime"),
            @Result(column = "status", property = "status")
    })
    List<Report> findPendingReports();

    @Update("UPDATE report SET status = #{status} WHERE id = #{id}")
    void updateStatus(Report report);

    // 新增管理员相关方法
    @Select("SELECT * FROM report ORDER BY create_time DESC")
    @ResultMap("reportMap")
    List<Report> findAll();

    @Select("SELECT * FROM report WHERE id = #{id}")
    @ResultMap("reportMap")
    Report findById(@Param("id") Integer id);

    @Update("UPDATE report SET status = #{status} WHERE id = #{id}")
    void updateStatusById(@Param("id") Integer id, @Param("status") String status);
}
